package iterator.improve;

import java.util.Iterator;
import java.util.List;

/**
 * 打印学院和系
 */
public class OutPutImpl {
    private List<College> colleges;

    public OutPutImpl(List<College> colleges) {
        this.colleges = colleges;
    }

    // 遍历所有学院和系
    public void printCollege() {
        Iterator<College> iterator = colleges.iterator();
        while (iterator.hasNext()) {
            College college = iterator.next();
            System.out.println("=== " + college.getName() + "=====");
            Iterator<Department> departmentIterator = college.createIterator();
            printDepartment(departmentIterator);
        }
    }

    //打印系
    private void printDepartment(Iterator<Department> iterator) {
        while (iterator.hasNext()) {
            Department d = iterator.next();
            System.out.println(d.getName());
        }
    }
}
